#include<iostream>
#include<unistd.h>
#include<cstdio>
#include<cerrno>
#include<cstring>
using namespace std;
extern int errno;


int main()
{
    //从键盘中读取消息，写到管道中，然后再读管道中的数据到显示器；
    //输入型参数；
    int pipearr[2] = {0};
    int n = pipe(pipearr);
    while(1)
    {

    
    if(n< 0)
    {
        cout<<"pipe error:"<<errno<<endl;
        perror("pipe");
    }
    char ch[1024] = {0};
    
    n = read(0,ch,sizeof(ch));
    if(n == -1)
    {
        cout<<"read fail:"<<errno<<endl;
        perror("read");
    }
    n = write(pipearr[1],ch,strlen(ch));
    if(n < 0)
    {
        cout<<"write fail"<<endl;
    }
    read(pipearr[0],ch,sizeof(ch));
    write(1,ch,strlen(ch));
    }
    return 0;
    
}